﻿using UnityEngine;
using System.Collections;
using Configs;

public class TowerObject : IUnitObject
{

    public TowerObject(IStage stage, ConfUnitObject confUnitObject) : base(stage, confUnitObject)
    {
        GetModule().GetOrNew<ModBlood>().SetOffsetPos(new Vector3(0, 2f, 0));
    }

    public static void OnEventLossHp(IUnitObject unitObj, int hp, IUnitObject attackUnitObj)
    {
        if (!(unitObj is TowerObject))
        {
            return;
        }

        Debug.Log("TowerObject[" + unitObj.GetId() + "]losshp:" + hp);

        unitObj.GetModule().Get<ModDamage>().BeDamaged(hp);
    }

    public static void OnEventDead(IUnitObject unitObj, IUnitObject attackUnitObj)
    {
        if (!(unitObj is TowerObject))
        {
            return;
        }

        Debug.Log("塔被推倒了：" + unitObj.GetId());

        if (unitObj.GetModule().Get<ModAttr>().GetGroup() == ModAttr.GROUP_RED)
        {
            UIManager.GetInstance().GetUI<ReStartUI>().SetResult(false);
        }
        else
        {
            UIManager.GetInstance().GetUI<ReStartUI>().SetResult(true);
        }
    }
}
